browser.runtime.onMessage.addListener(request => {
  // debugger
  if (request.from === "webPage") return;
  request.from = "content";
  request.to = "webPage";
  window.postMessage(request);
  return Promise.resolve({ response: true });
});
/**@param {Message} request */
function getAppName(request) {
  /**@type {Configs} Configs*/
  Configs.app.name = request.content
  request.from = LayerType.CONTENT
  request.to = LayerType.BACKGROUND
  browser.runtime.sendMessage(request)
}
window.addEventListener('message', _ => {
  /**@type {Message}*/
  const request = _.data;
  // debugger
  if (request?.from !== LayerType.WEBPAGE) return;
  if (request.to === LayerType.BACKGROUND)
    request.version += 1;
  { browser.runtime.sendMessage(request) }
  if (request.to === LayerType.CONTENT) {
    const method = eval(`${request.responseCall}`);
    method(request)
  }
})
window.postMessage(
  new Message({
    from: LayerType.CONTENT,
    to: LayerType.WEBPAGE,
    content: `new URL(window.location.href)
  .pathname
  .replaceAll('/','')
  .replace(/^([a-zA-Z0-9])/,
    (matched,_1) => _1.toString().toUpperCase())`,
    responseCall: 'getAppName',
    responseTo: LayerType.CONTENT,
    version: 0
  }))
browser.runtime.sendMessage(new Message({
  from: LayerType.CONTENT,
  to: LayerType.BACKGROUND,
  responseCall: 'pageActioniconColor',
  version: 0,
}))
